import Vue from 'vue'
import VueRouter from 'vue-router'
// 命名为index.vue，后面的index.vue可以省略不写
// import Home from '../views/Home/index.vue'

Vue.use(VueRouter)
// 路由跳转
const routes = [
  // 默认触发访问/home路由
  {
    path: '/',
    component: () => import('@/App'),
    redirect: '/login',
    children: [
      // home
      {
        path: '/index',
        component: () => import('@/views/home/Index'),
        redirect: '/home',
        children:[
           // 首页
           {
            path: '/home',
            component: () => import('@/views/home/Home')
          },
          // 好友
          {
            path: '/friends',
            component: () => import('@/views/Friends')
          },
          // 订单
          {
            path: '/order',
            component: () => import('@/views/order/OrderList')
          },
          // 用户
          {
            path: '/user',
            component: () => import('@/views/user/UserInfo')
          },
          // 座位
          {
            path: '/seats/:id',
            component: () => import('@/views/home/conpoments/Seats')
          }
        ]
      },
      // 静态跳转 登录与注册 找回密码
      {
        path: '/login',
        component: () => import('@/views/common/Login')
      },
      {
        path: '/register',
        component: () => import('@/views/common/Register')
      },
      {
        path: '/resetPassword',
        component: () => import('@/views/common/ResetPassword')
      },
      {
        path: '/settings',
        component: () => import('@/views/common/Settings')
      },
      {
        path: '/pay',
        component: () => import('@/views/common/Pay')
      },
    ]
  },
]

const router = new VueRouter({
  routes
})
// 全局路由守护
router.beforeEach((to, from, next) => {
  console.log(from.path, to.path) //从哪来  到哪去
  next()
})

export default router
